package com.qf.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
/**
 * @author ZERO
 * @date 2021/12/24 10:15
 */

/**
 *@program: com.qf.config
 *@description:
 *@author: ZERO
 *@create: 2021/12/24 10:15
 */
@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {

    @Override
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("localhost:9200")
                .build();

        return RestClients.create(clientConfiguration).rest();
    }
    //模板对象
    @Bean
    public ElasticsearchRestTemplate elasticsearchRestTemplate(){
        ElasticsearchRestTemplate template = new ElasticsearchRestTemplate(elasticsearchClient());
        return template;
    }
}
